





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>从源码安装 &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="NNPACK Contrib Installation" href="nnpack.html" />
    <link rel="prev" title="安装 TVM" href="index.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html">
          

          
            
            <img src="../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">安装 TVM</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">从源码安装</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#developers-get-source-from-github">开发者： 从 GitHub 获取源码</a></li>
<li class="toctree-l3"><a class="reference internal" href="#build-the-shared-library">编译共享库</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#building-with-a-conda-environment">构建一个 Conda 环境</a></li>
<li class="toctree-l4"><a class="reference internal" href="#building-on-windows">基于Windows构建</a></li>
<li class="toctree-l4"><a class="reference internal" href="#building-rocm-support">构建 ROCm 支持</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#python-package-installation">Python包安装</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#tvm-package">TVM包</a></li>
<li class="toctree-l4"><a class="reference internal" href="#python-dependencies">Python 依赖项</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#install-contrib-libraries">安装 Contrib 库</a><ul>
<li class="toctree-l4"><a class="reference internal" href="nnpack.html">NNPACK Contrib Installation</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#enable-c-tests">使用 C++ 测试</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="docker.html">Docker 镜像</a></li>
<li class="toctree-l2"><a class="reference internal" href="tlcpack.html">TLCPack</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../how_to/index.html">How To Guides</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../arch/index.html">Design and Architecture</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../topic/microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../topic/vta/index.html">VTA: Versatile Tensor Accelerator</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../reference/langref/index.html">语言参考</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/api/python/index.html">Python API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/api/links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> <span class="br-arrow">></span></li>
        
          <li><a href="index.html">安装 TVM</a> <span class="br-arrow">></span></li>
        
      <li>从源码安装</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/install/from_source.rst.txt" rel="nofollow"> <img src="../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="install-from-source">
<span id="id1"></span><h1>从源码安装<a class="headerlink" href="#install-from-source" title="永久链接至标题">¶</a></h1>
<p>此页面提供了有关如何在各种系统上从头开始编译和安装 TVM 的说明。 它有两个步骤组成：</p>
<ol class="arabic simple">
<li><p>首先从 C++ 代码编译共享库 （Linux: <cite>libtvm.so</cite>，macOS: <cite>libtvm.dylib</cite>，windows: <cite>libtvm.dll</cite>）。</p></li>
<li><p>语言包的设置 （例如： Python包）</p></li>
</ol>
<p>首先, 从 <a class="reference external" href="https://tvm.apache.org/download">下载页</a> 下载 TVM 源代码</p>
<div class="section" id="developers-get-source-from-github">
<h2>开发者： 从 GitHub 获取源码<a class="headerlink" href="#developers-get-source-from-github" title="永久链接至标题">¶</a></h2>
<p>您也可以选择从 github 克隆源代码库。 使用 <code class="docutils literal notranslate"><span class="pre">--recursive</span></code> 选项克隆子模块很重要</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git clone --recursive https://github.com/apache/tvm tvm
</pre></div>
</div>
<p>对于使用github工具的windows用户，可以打开 git shell，输入以下命令。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git submodule init
git submodule update
</pre></div>
</div>
</div>
<div class="section" id="build-the-shared-library">
<span id="build-shared-library"></span><h2>编译共享库<a class="headerlink" href="#build-the-shared-library" title="永久链接至标题">¶</a></h2>
<p>我们的目标是编译共享库：</p>
<blockquote>
<div><ul class="simple">
<li><p>在 Linux 上，目标库是 <cite>libtvm.so</cite> 和 <cite>libtvm_runtime.so</cite></p></li>
<li><p>在 macOS 上，目标库是 <cite>libtvm.dylib</cite> 和 <cite>libtvm_runtime.dylib</cite></p></li>
<li><p>在 Windows 上，目标库是 <cite>libtvm.dll</cite> 和 <cite>libtvm_runtime.dll</cite></p></li>
</ul>
</div></blockquote>
<p>也可以只 <a class="reference internal" href="../how_to/deploy/index.html#deploy-and-integration"><span class="std std-ref">构建 runtime</span></a> 库。</p>
<p>编译 TVM 库的最低要求是：</p>
<blockquote>
<div><ul class="simple">
<li><p>支持 C++ 14（g++-5 或更高）的最新 C++ 编译器</p></li>
<li><p>CMake 3.5 版本或者更高版本</p></li>
<li><p>我们强烈建议使用 LLVM 编译以启用所有功能。</p></li>
<li><p>如果要使用 CUDA，则需要 CUDA 工具包版本 &gt;= 8.0。如果您是从旧版本升级，请确保清除旧版本并在安装后重新启动。</p></li>
<li><p>在 macOS 上，您可能需要安装 <cite>Homebrew &lt;https://brew.sh&gt;</cite> 来轻松安装和管理依赖项。</p></li>
<li><p>还需要 Python。 避免使用不受 <a class="reference external" href="https://github.com/apache/tvm/issues/8577">支持</a> 的 Python 3.9.X+，3.7.X+ 和 3.8.X+ 应该得到很好的支持。</p></li>
</ul>
</div></blockquote>
<p>要在 Ubuntu/Debian 等 linux 操作系统上安装, 请满足这些最小先决条件，请执行（在终端中）:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
</pre></div>
</div>
<p>使用 Homebrew 为运行 Intel 或 M1 处理器的 macOS 安装所需的依赖项。 您必须遵循 Homebrew 指定的安装后步骤以确保正确安装和配置依赖项：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>brew install gcc git cmake
brew install llvm
brew install python@3.8
</pre></div>
</div>
<p>我们用 cmake 来建造 library。TVM 的配置可以通过编辑 <cite>config.cmake</cite> 或将 cmake 标志传递到命令行进行修改：</p>
<ul>
<li><p>首先，检查系统中的cmake。如果您没有cmake，可以从`官方网站 &lt;<a class="reference external" href="https://cmake.org/download/">https://cmake.org/download/</a>&gt;`_获取最新版本</p></li>
<li><p>首先创建一个构建目录，将``cmake/config.cmake``复制到该目录。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mkdir build
cp cmake/config.cmake build
</pre></div>
</div>
</li>
<li><p>编辑``build/config.cmake``以自定义编译选项</p>
<ul>
<li><p>在macOS上,对于某些版本的Xcode,您需要在LDFLAGS中添加``-lc++abi``,否则会出现链接错误。</p></li>
<li><p>将``设置(USE_CUDA OFF)``更改为``设置(USE_CUDA ON)``以启用CUDA后端。对您要构建的其他后端和库(OpenCL, RCOM, METAL, VULKAN, …)执行相同的操作。</p></li>
<li><p>为了帮助调试，请确保已使用``设置(USE_GRAPH_EXECUTOR ON)``和``设置(USE_PROFILER ON)``启用嵌入式图形执行器和调试功能``</p></li>
<li><p>要使用IRs进行调试, <a href="#id1"><span class="problematic" id="id2">``</span></a>设置(USE_RELAY_DEBUG ON)``并设置环境变量`TVM_LOG_DEBUG`。</p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">TVM_LOG_DEBUG</span><span class="o">=</span><span class="m">1</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
</li>
<li><p>TVM 依赖 LLVM 用于 CPU 代码生成。我们强烈建议您在进行构建的时候选用 LLVM。</p>
<ul class="simple">
<li><p>使用LLVM构建需要LLVM 4.0或更高版本。请注意，默认apt的LLVM版本可能低于4.0。</p></li>
<li><p>因为从源代码构建LLVM需要很长时间,所以您可以从`LLVM下载页面&lt;<a class="reference external" href="http://releases.llvm.org/download.html">http://releases.llvm.org/download.html</a>&gt;`_.下载预构建版本的LLVM。</p>
<ul>
<li><p>解压到一个特定的位置，修改``build/config.cmake``以添加``set(USE_LLVM /path/to/your/llvm/bin/llvm-config)``</p></li>
<li><p>您还可以直接设置``set(USE_LLVM ON)``并使用cmake搜索可用版本的LLVM。</p></li>
</ul>
</li>
<li><p>您还可以使用`LLVM Nightly Ubuntu Build &lt;<a class="reference external" href="https://apt.llvm.org/">https://apt.llvm.org/</a>&gt;`_</p>
<ul>
<li><p>请注意，apt-package会在`llvm-config``后加上版本号。例如，如果您安装了LLVM 10软件包，请设置``set(USE_LLVM llvm-config-10)``</p></li>
</ul>
</li>
</ul>
</li>
<li><p>接下来我们可以建立tvm和相关的库。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span> build
cmake ..
make -j4
</pre></div>
</div>
<ul class="simple">
<li><p>您还可以使用Ninja构建系统而不是Unix Makefiles。Ninja可以比Makefiles更快地进行构建。</p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span> build
cmake .. -G Ninja
ninja
</pre></div>
</div>
<ul>
<li><p>There is also a makefile in the top-level tvm directory that can
automate several of these steps.  It will create the build
directory, copy the default <code class="docutils literal notranslate"><span class="pre">config.cmake</span></code> to the build
directory, run cmake, then run make.</p>
<p>可以使用环境变量``TVM_BUILD_PATH``指定生成目录。如果``TVM_BUILD_PATH``未设置，则makefile假定生成文件使用TVM内的``build``目录。<a href="#id1"><span class="problematic" id="id2">``</span></a>TVM_BUILD_PATH``指定的路径可以是绝对路径，也可以是相对于基本TVM目录的路径``TVM_BUILD_PATH``也可以设置为空间分隔路径列表，在这种情况下，将生成列出的所有路径。</p>
<p>如果使用备用生成目录，则应在运行时设置环境变量``TVM_LIBRARY_PATH``，指向编译的``libtvm.so``和``libtvm_runtime.so``的位置。如果未设置，tvm将根据tvm python module的位置进行查看。与``TVM_BUILD_PATH``不同，这必须是绝对路径。</p>
</li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># Build in the &quot;build&quot; directory</span>
make

<span class="c1"># Alternate location, &quot;build_debug&quot;</span>
<span class="nv">TVM_BUILD_PATH</span><span class="o">=</span>build_debug make

<span class="c1"># Build both &quot;build_release&quot; and &quot;build_debug&quot;</span>
<span class="nv">TVM_BUILD_PATH</span><span class="o">=</span><span class="s2">&quot;build_debug build_release&quot;</span> make

<span class="c1"># Use debug build</span>
<span class="nv">TVM_LIBRARY_PATH</span><span class="o">=</span>~/tvm/build_debug python3
</pre></div>
</div>
</li>
</ul>
<p>如果一切顺利， 我们就可以进入 <a class="reference internal" href="#python-package-installation"><span class="std std-ref">Python包安装</span></a></p>
<div class="section" id="building-with-a-conda-environment">
<span id="build-with-conda"></span><h3>构建一个 Conda 环境<a class="headerlink" href="#building-with-a-conda-environment" title="永久链接至标题">¶</a></h3>
<p>Conda 是获取运行 TVM 所需依赖项的一种非常方便的方法。首先，如果您的系统中还没有 <cite>conda</cite>，请按照 <cite>conda</cite> 的安装指南&lt;<a class="reference external" href="https://docs.conda.io/projects/conda/en/latest/user-guide/install/">https://docs.conda.io/projects/conda/en/latest/user-guide/install/</a>&gt;`_ 安装 <cite>miniconda</cite> 或 <cite>anaconda</cite>。在 <cite>conda</cite> 环境中运行以下命令：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># Create a conda environment with the dependencies specified by the yaml</span>
conda env create --file conda/build-environment.yaml
<span class="c1"># Activate the created environment</span>
conda activate tvm-build
</pre></div>
</div>
<p>上面的命令将安装所有必要的构建依赖项，例如cmake和LLVM。然后您可以在最后一节中运行标准构建过程。</p>
<p>如果要在conda环境之外使用编译后的二进制文件，可以将LLVM设置为静态链接模式``set(USE_LLVM “llvm-config –link-static”)``。这样，生成的库将不依赖于conda环境中的动态LLVM库。</p>
<p>上面的说明显示了如何使用conda来提供构建libtvm所需的构建依赖项。如果您已经使用conda作为软件包管理器并且希望直接将tvm作为conda软件包进行构建和安装，则可以按照以下说明进行操作：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>conda build --output-folder<span class="o">=</span>conda/pkg  conda/recipe
<span class="c1"># Run conda/build_cuda.sh to build with cuda enabled</span>
conda install tvm -c ./conda/pkg
</pre></div>
</div>
</div>
<div class="section" id="building-on-windows">
<h3>基于Windows构建<a class="headerlink" href="#building-on-windows" title="永久链接至标题">¶</a></h3>
<p>使用cmake通过MSVC构建TVM支持。您将需要安装visual studio编译器。要求VS最低的版本为**Visual Studio Community 2015 Update 3**。我们建议:ref:<a href="#id1"><span class="problematic" id="id2">`</span></a>build-with-conda`以获得必要的生产环境并激活tvm的构建环境。您可以运行以下命令来生成</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>mkdir build
<span class="nb">cd</span> build
cmake -A x64 -Thost<span class="o">=</span>x64 ..
<span class="nb">cd</span> ..
</pre></div>
</div>
<p>上面的命令在build目录下生成解决方案的文件。您可以运行以下指令来生成</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake --build build --config Release -- /m
</pre></div>
</div>
</div>
<div class="section" id="building-rocm-support">
<h3>构建 ROCm 支持<a class="headerlink" href="#building-rocm-support" title="永久链接至标题">¶</a></h3>
<p>目前，仅linux上支持ROCm，因此所有的指令都是用linux编写的。</p>
<ul class="simple">
<li><p>设置``set(USE_ROCM ON)``，将ROCM_PATH设置为正确的路径。</p></li>
<li><p>您需要首先从ROCm安装HIP runtime。确保安装系统中已经安装了ROCm。</p></li>
<li><p>安装最新稳定版本的LLVM（v6.0.1）和LLD，确保``ld.lld``通过命令行可用。</p></li>
</ul>
</div>
</div>
<div class="section" id="python-package-installation">
<span id="id2"></span><h2>Python包安装<a class="headerlink" href="#python-package-installation" title="永久链接至标题">¶</a></h2>
<div class="section" id="tvm-package">
<h3>TVM包<a class="headerlink" href="#tvm-package" title="永久链接至标题">¶</a></h3>
<p>根据您的开发环境，您可能希望使用虚拟环境和包管理器（如``virtualenv``或者``conda``）来管理python的包和生产环境。</p>
<p>安装和维护python开发环境。</p>
<p>python软件包位于`tvm/python`中。安装该软件包有两种方法：</p>
<dl>
<dt>方法 1</dt><dd><p>此方法**推荐给可能更改代码的开发人员**。</p>
<p>设置环境变量`PYTHONPATH`来告诉python在哪里可以找到库。例如，假设我们克隆目录`/path/to/tvm`上的`tvm`，那么我们可以在`~/.bashrc`中添加以下行。一旦您提取代码并重建项目，这些更改将立即反映出来（无需再次调用``setup``）</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">TVM_HOME</span><span class="o">=</span>/path/to/tvm
<span class="nb">export</span> <span class="nv">PYTHONPATH</span><span class="o">=</span><span class="nv">$TVM_HOME</span>/python:<span class="si">${</span><span class="nv">PYTHONPATH</span><span class="si">}</span>
</pre></div>
</div>
</dd>
<dt>方法 2</dt><dd><p>通过 <cite>setup.py</cite> 安装 TVM python bindings</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># install tvm package for the current user</span>
<span class="c1"># NOTE: if you installed python via homebrew, --user is not needed during installaiton</span>
<span class="c1">#       it will be automatically installed to your user directory.</span>
<span class="c1">#       providing --user flag may trigger error during installation in such case.</span>
<span class="nb">export</span> <span class="nv">MACOSX_DEPLOYMENT_TARGET</span><span class="o">=</span><span class="m">10</span>.9  <span class="c1"># This is required for mac to avoid symbol conflicts with libstdc++</span>
<span class="nb">cd</span> python<span class="p">;</span> python setup.py install --user<span class="p">;</span> <span class="nb">cd</span> ..
</pre></div>
</div>
</dd>
</dl>
</div>
<div class="section" id="python-dependencies">
<h3>Python 依赖项<a class="headerlink" href="#python-dependencies" title="永久链接至标题">¶</a></h3>
<p>请注意，如果您要安装到托管本地环境， 如 <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code>，则不需要  <code class="docutils literal notranslate"><span class="pre">--user</span></code> 标志。</p>
<blockquote>
<div><ul class="simple">
<li><p>必要的依赖：</p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pip3 install --user numpy decorator attrs
</pre></div>
</div>
<ul class="simple">
<li><p>如果你想使用 RPC Tracker</p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pip3 install --user tornado
</pre></div>
</div>
<ul class="simple">
<li><p>如果要使用 auto-tuning 模块</p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pip3 install --user tornado psutil xgboost cloudpickle
</pre></div>
</div>
</div></blockquote>
<p>请注意，在 M1 macs 上，您可能在安装 xgboost / scipy 时遇到问题。 scipy 和 xgboost 需要安装一些额外的依赖项，包括 openblas 及其依赖项。 使用以下命令安装具有所需依赖项和配置的 scipy 和 xgboost。 解决方法是执行以下命令：</p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>brew install openblas gfortran

pip install pybind11 cython pythran

<span class="nb">export</span> <span class="nv">OPENBLAS</span><span class="o">=</span>/opt/homebrew/opt/openblas/lib/

pip install scipy --no-use-pep517

pip install xgboost
</pre></div>
</div>
</div></blockquote>
</div>
</div>
<div class="section" id="install-contrib-libraries">
<h2>安装 Contrib 库<a class="headerlink" href="#install-contrib-libraries" title="永久链接至标题">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="nnpack.html">NNPACK Contrib Installation</a></li>
</ul>
</div>
</div>
<div class="section" id="enable-c-tests">
<span id="install-from-source-cpp-tests"></span><h2>使用 C++ 测试<a class="headerlink" href="#enable-c-tests" title="永久链接至标题">¶</a></h2>
<p>我们使用 <a class="reference external" href="https://github.com/google/googletest">Google Test</a> 来驱动 TVM 中的 C++ 测试。 安装 GTest 的最简单方法是从源代码。</p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git clone https://github.com/google/googletest
<span class="nb">cd</span> googletest
mkdir build
<span class="nb">cd</span> build
cmake -DBUILD_SHARED_LIBS<span class="o">=</span>ON ..
make
sudo make install
</pre></div>
</div>
</div></blockquote>
<p>安装 GTest 后，可以使用 <code class="docutils literal notranslate"><span class="pre">./tests/scripts/task_cpp_unittest.sh</span></code> 或仅使用 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">cpptest</span></code> 构建和启动 C++ 测试。</p>
</div>
</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="nnpack.html" class="btn btn-neutral float-right" title="NNPACK Contrib Installation" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="index.html" class="btn btn-neutral float-left" title="安装 TVM" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>